package elm.dao.impl;

import elm.dao.AdminDao;
import elm.pojo.Admin;
import util.DruidUtil;

import java.sql.*;

public class AdminDaoImpl implements AdminDao {
    private Connection conn;
    private PreparedStatement pstmt;
    private ResultSet rs;


    @Override
    public Admin login(String adminName, String password) {
        Admin admin = null;
        try {
            conn = DruidUtil.getConnection();
            pstmt = conn.prepareStatement("select * from admin where adminName=? and password=?");
            pstmt.setString(1,adminName);
            pstmt.setString(2,password);
            rs = pstmt.executeQuery();
            if(rs.next()){
                admin= new Admin(rs.getString(2),rs.getString(3));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            DruidUtil.closeAll(rs,pstmt,conn);
        }
        return admin;
    }
}
